﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using TellStick;
using TellStick.Models;
using TellStick.Protocols;

namespace Tellstick_Registrator
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            this.DataContext = this;
            FillTreeview();
        }


        private void FillTreeview()
        {
            var registerableDevices = TellStick.TellStickDevice.RegisterableDevices;
            foreach (var registerableDevice in registerableDevices)
            {
                var parent = new TreeViewItem() 
                                    { Header = registerableDevice.Key.DisplayName, 
                                      Tag = registerableDevice};
                foreach (var tellStickSettingType in registerableDevice.Value)
                {
                    var child = new TreeViewItem() 
                                    { Header = EnumHelper.GetSettingsDisplayName(tellStickSettingType),
                                      Tag = (tellStickSettingType) };
                    parent.Items.Add(child);
                }

                tvwPossibleDevices.Items.Add(parent);

            }
        }

        private void tvwPossibleDevices_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
        {
            //TreeView tv = (TreeView)sender;
            //flowLayoutPanel1.Controls.Clear();
            //if (tv.SelectedNode.Tag is TellStickSettingTypes)
            //{
            //    if (device != null)
            //        tbName.Text = device.Name;

            //    ModelBase m = (ModelBase)tv.SelectedNode.Parent.Tag;
            //    foreach (Parameter p in m.Protocol.GetParameters((TellStickSettingTypes)tv.SelectedNode.Tag))
            //    {
            //        ParameterControl pc = new ParameterControl(p);
            //        if (device != null && ((TellStickSettingTypes)tv.SelectedNode.Tag) == device.ControlType)
            //            pc.TextValue = device.GetParameter(p.Type);
            //        flowLayoutPanel1.Controls.Add(pc);
            //    }
            //}
        }

        private void btnRegister_Click(object sender, RoutedEventArgs e)
        {
            lblValue1.Label = "sdgsdg";
            int i = 0;
        }

        private void lblValue1_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            int i = 0;
        }

    }
}
